﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using System.Buffers;
using System.IO;
using System.Threading.Tasks;
using Zeus.Mvc.Results;
using Zeus.Mvc.Results.Implementations;

namespace ZeusCore.Performance.Test
{

    public class DefaultZeusResultExecutorPerformance
    {
        public async Task<ActionContext> ExecuteAsyncPerformanceTest(ActionContext actionContext)
        {
            var result = new ZeusResult(new { data = "{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}{Code:5202,Data:null,GuidRequest:null,Message:[Code=5202][Message=CANCELQRCODEORDER FAILD!PRICE ERROR][InnerMessage=]}" });
            actionContext = actionContext ?? GetActionContext();
            await result.ExecuteResultAsync(actionContext);
            return actionContext;
        }

        private static HttpContext GetHttpContext()
        {
            var httpContext = new DefaultHttpContext();
            httpContext.Response.Body = new MemoryStream();

            var executor = new ZeusResultExecutor(
                new TestHttpResponseStreamWriterFactory(),
                NullLogger<ZeusResultExecutor>.Instance,
                ArrayPool<char>.Shared);

            var services = new ServiceCollection();
            services.AddSingleton<IZeusResultExecutor>(executor);
            httpContext.RequestServices = services.BuildServiceProvider();

            return httpContext;
        }

        public static ActionContext GetActionContext()
        {
            return new ActionContext(GetHttpContext(), new RouteData(), new ActionDescriptor());
        }
    }

}
